﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WXYW.BLL;
using WXYW.DAL;

namespace WXYW
{
    public partial class AddProductType : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                ProductClassService service = new ProductClassService();
                productClassDDL.DataSource = service.GetAllClassWithSelectOne();
                productClassDDL.DataTextField = "Name";
                productClassDDL.DataValueField = "ID";
                productClassDDL.DataBind();
            }
        }

        protected void SaveBtn_Click(object sender, EventArgs e)
        {
            if (productClassDDL.SelectedIndex > 0)
            {
                ProductClassService service = new ProductClassService();
                ProductType productType = new ProductType();
                productType.ProductClass = service.GetProductClass(Convert.ToInt32(productClassDDL.SelectedValue));
                productType.ProductTypeName = productTypeTxtBox.Text.Trim();
                service.AddProductType(productType);
                Response.Write(string.Format("<script language='JavaScript'> alert( '信息保存成功！');location.href= 'AddProductType.aspx' </script> "));
            }
            else
            {
                Response.Write(string.Format("<script language='JavaScript'> alert( '请选择产品类别！');location.href= 'AddProductType.aspx' </script> "));
            }
        }
    }
}
